#include <iostream>
#include "julia.hpp"


Julia::Julia(complex<double> c, int width, int height, 
	     int max_iter, double left, double right, 
	     double bottom, double top):
    AFractal(width, height, max_iter, left, right, bottom, top), c(c)
{ }


void Julia::render(FBitmap &bm, const Colormap &cm)
{
    bm = FBitmap(width, height);
    float xstep = (right - left) / (width-1);
    float ystep = (top - bottom) / (height-1);
    cout << bm.height() << " x " << bm.width() << endl;
    for (int i = 0; i < bm.height(); i++) {
	for (int j = 0; j < bm.width(); j++) {
	    complex<double> z(left + j*xstep, bottom + i*ystep);
	    int iter_num;
	    for (iter_num = 0; iter_num < max_iter-1; iter_num++) {
		z = z*z + c;
		if (abs(z) > 2.0)
		    break;
	    }
	    float r, g, b;
	    cm.gen_color(iter_num, z, r, g, b);
	    bm.set_pixel(i, j, r, g, b);
        }
    }
}
